xen: Introduce non-broken hypercalls for the paging mempool size
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 21 Oct 2022 13:13:00 +0000 (14:13 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 17 Nov 2022 16:51:51 +0000 (16:51 +0000)
commit22b20bd98c025e06525410e3ab3494d5e63489f7
treea405fdbefebcf2911be7f042a684a0dc38b73e4f
parente5ac68a0110cb43a3a0bc17d545ae7a0bd746ef9
xen: Introduce non-broken hypercalls for the paging mempool size

The existing XEN_DOMCTL_SHADOW_OP_{GET,SET}_ALLOCATION have problems:

 * All set_allocation() flavours have an overflow-before-widen bug when
   calculating "sc->mb << (20 - PAGE_SHIFT)".
 * All flavours have a granularity of 1M.  This was tolerable when the size of
   the pool could only be set at the same granularity, but is broken now that
   ARM has a 16-page stopgap allocation in use.
 * All get_allocation() flavours round up, and in particular turn 0 into 1,
   meaning the get op returns junk before a successful set op.
 * The x86 flavours reject the hypercalls before the VM has vCPUs allocated,
   despite the pool size being a domain property.
 * Even the hypercall names are long-obsolete.

Implement a better interface, which can be first used to unit test the
behaviour, and subsequently correct a broken implementation.  The old
interface will be retired in due course.

The unit of bytes (as opposed pages) is a deliberate API/ABI improvement to
more easily support multiple page granularities.

This is part of XSA-409 / CVE-2022-33747.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
tools/include/xenctrl.h
tools/libs/ctrl/xc_domain.c
xen/arch/arm/p2m.c
xen/arch/x86/include/asm/hap.h
xen/arch/x86/include/asm/shadow.h
xen/arch/x86/mm/hap/hap.c
xen/arch/x86/mm/paging.c
xen/arch/x86/mm/shadow/common.c
xen/common/domctl.c
xen/include/public/domctl.h
xen/include/xen/domain.h